package com.auto.learning.view;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.auto.learning.R;

public class PupPayDialog {
	private PopupWindow popupWindow;
	private Context context;
	private RelativeLayout pay_wechat, pay_alipay;
	private TextView tv_money;
	private String str = "请选择支付方式,支付金额为:￥";
	
	private OnPayItemClick onPayItemClick;
	
	// 支付提示框
	public PupPayDialog(Context context, final int money) {
		this.context = context;
		View view = LayoutInflater.from(context).inflate(R.layout.pup_pay_dialog, null);
		popupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, true);
		pay_wechat = (RelativeLayout) view.findViewById(R.id.pay_wechat);
		pay_alipay = (RelativeLayout) view.findViewById(R.id.pay_alipay);
		pay_wechat.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (onPayItemClick != null) {
					onPayItemClick.onWechatPayClick(money);
				}
				dismiss();
			}
		});
		pay_alipay.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (onPayItemClick != null) {
					onPayItemClick.onAliPayClick(money);
				}
				dismiss();
			}
		});
		tv_money = (TextView) view.findViewById(R.id.tv_money);
		tv_money.setText(str + money);
		popupWindow.setFocusable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());

	}
	public void setMoney(String money){
		tv_money.setText(str+money);
	}

	public void show(View view) {
		popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
	}

	public void dismiss() {
		popupWindow.dismiss();
	}
	
	public void setOnPayItemClick(OnPayItemClick onPayItemClick) {
		this.onPayItemClick = onPayItemClick;
	}
	
	public interface OnPayItemClick{
		public void onAliPayClick(int money);
		public void onWechatPayClick(int money);
	}
}
